package com.tobeface.sns.domain.life;

import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.collect.Sets;
import com.kissme.core.domain.AbstractDomain;

/**
 * 
 * @author loudyn
 * 
 */
public class LifeTwitter extends AbstractDomain {

	private static final long serialVersionUID = 1L;

	private static final Pattern TOPIC_PATTERN = Pattern.compile("#([^#\\s&&[\u0000-\u007f\u4e00-\u9fa5]]+)#\\s");
	private static final Pattern FRIEND_PATTERN = Pattern.compile("@([^@\\s&&[\u0000-\u007f\u4e00-\u9fa5]]+)\\s");

	private String content;
	private String tags;

	private long createTime;

	public LifeTwitter() {
		this.createTime = System.currentTimeMillis();
	}

	public Set<String> mentionedTopics() {
		Set<String> topics = Sets.newHashSet();

		Matcher m = TOPIC_PATTERN.matcher(getContent());
		if (m.find()) {
			topics.add(m.group(1));
		}

		return topics;
	}

	public Set<String> metionedFriends() {
		Matcher m = FRIEND_PATTERN.matcher(getContent());
		Set<String> friends = Sets.newHashSet();
		while (m.find()) {
			friends.add(m.group(1));
		}

		return friends;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public long getCreateTime() {
		return createTime;
	}

	protected LifeTwitter setCreateTime(long createTime) {
		this.createTime = createTime;
		return this;
	}

}
